<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="misc.*,data.UploadLog,data.DownloadLog,data.File,controller.LogViewController"%>
<%@page import="java.util.LinkedList, java.text.SimpleDateFormat"%>
<%@page import="data.AuthorizationSession"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><%=Configurations.title%>View file logs</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<% 
AuthorizationSession.checkAuthorizationToken(request,response,true);

if(request.getParameter("file")==null)
{
    %>
    <div class="error">Please specify a file!</div>
    <%
}
else
{   
    LogViewController control = new LogViewController(); 
    long id=control.retrieveFileID(request.getParameter("file"));
    UploadLog this_upload = control.retrieveUploadLog(id);
%>
<h1>File: <%=this_upload.getFileName() %></h1>
<b>Username of the uploader: <%=this_upload.getUsername() %></b>
<hr/>
<h2>Download logs</h2>
    <table class="display">
        <tr class="heading">
          <td>No.</td>
          <td>IP address</td>
          <td>Start date</td>
          <td>Finished date</td>
          <td>Start time</td>
          <td>Finished time</td>
          <td>Username</td>
        </tr>
        <%
        LinkedList<DownloadLog> downloads = control.retrieveDownloadLog(id);
        for(int i=0;i<downloads.size();i++){
            DownloadLog this_download = downloads.get(i);
        %>
        <tr class="row">
          <td><%=(i+1) %></td>
          <td><%=this_download.getIPaddress() %></td>
          <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_download.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_download.getFinish()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_download.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_download.getFinish()).toString() %></td>
           <td><%if(this_download.getUsername()==null){%>Unregistered<%}else{%><%=this_download.getUsername()%><%}%></td>
        </tr>
        <%}%>
    </table>
    <br/>
<hr/>
<h2>Upload logs</h2>
    <table class="display">
        <tr class="heading">
          <td>File name</td>
          <td>File size</td>
          <td>File type</td>
          <td>IP address</td>
          <td>Start date</td>
          <td>Finished date</td>
          <td>Start time</td>
          <td>Finished time</td>
          <td>Password protected</td>
        </tr>
        <tr class="row">
          <td><%=this_upload.getFileName() %></td>
          <td><%=File.convertToMB(this_upload.getFilesize()) %></td>
          <td><%=this_upload.getFiletype() %></td>
          <td><%=this_upload.getIPaddress() %></td>
           <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_upload.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("dd MMMMM yyyy").format(this_upload.getFinish()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_upload.getStart()).toString() %></td>
          <td><%=new SimpleDateFormat("h:mm:ss a z").format(this_upload.getFinish()).toString() %></td>
          <td><%if(!this_upload.isFileIsProtected()){%>Nope<%}else{%><%=this_upload.getFileHashedPassword()%><%}%></td>
        </tr>
    </table>
    <br/>
<%}%>
<hr/>
<form>
    <input type=button value="Close Window" onclick="javascript:window.close();"/>
</form> 
</body>
</html>